package com.huashi.demo;

import java.util.LinkedList;

public class MinStack {

    LinkedList<Integer> list ;

    /** initialize your data structure here. */
    public MinStack() {
        list = new LinkedList<>();
    }

    public void push(int x) {
        list.addFirst(x);
    }

    public void pop() {
        if (!list.isEmpty()){
            list.removeFirst();
        }
    }

    public int top() {
        if (!list.isEmpty()){
            return list.getFirst();
        }else {
            return -1;
        }
    }

    public int min() {
        if (!list.isEmpty()){
            return list.stream().min(Integer::compare).get();
        }
        else {
            return -1;
        }
    }

}